package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.Options;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@DubboService
public class OptionsApiImpl implements OptionsApi{
    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public List<Options> findOptions(String id) {
        Query query = Query.query(Criteria.where("questionId").is(id));
        List<Options> options = mongoTemplate.find(query, Options.class);
        return options;
    }

    @Override
    public List<Options> findByIds(List<ObjectId> optionId) {

        Query query = Query.query(Criteria.where("id").in(optionId));
        List<Options> options = mongoTemplate.find(query, Options.class);

        return options;
    }
}
